#include <dao.h>
#include <btBulletDynamicsCommon.h>

#include "btClock.h"

static void construct(DaoContext *ctx, DValue *p[], int N) {
    btClock* ptr = new btClock();

    DaoCData *cdata = DaoContext_PutCData(ctx, ptr, &btClockTyper);
};

static void destruct(void *self) {
    delete (btClock*) self;
}

static void getTimeMicroseconds(DaoContext *ctx, DValue *p[], int N) {
    btClock* ptr = (btClock*) DaoCData_GetData(p[0]->v.cdata);

    DaoContext_PutInteger(ctx, ptr->getTimeMicroseconds());
}

static void getTimeMilliseconds(DaoContext *ctx, DValue *p[], int N) {
    btClock* ptr = (btClock*) DaoCData_GetData(p[0]->v.cdata);

    DaoContext_PutInteger(ctx, ptr->getTimeMilliseconds());
}

static void reset(DaoContext *ctx, DValue *p[], int N) {
    btClock* ptr = (btClock*) DaoCData_GetData(p[0]->v.cdata);

    ptr->reset();
}

static DaoFuncItem meth[] = {
    { construct,	        "btClock()" },

    { getTimeMicroseconds,      "getTimeMicroseconds(self:btClock) => int" },
    { getTimeMilliseconds,      "getTimeMilliseconds(self:btClock) => int" },
    { reset,                    "reset(self:btClock)" },
    { NULL, NULL }
};

DaoTypeBase btClockTyper = {
    "btClock",
    NULL,
    NULL,               /* constant */
    meth,       	/* methods */
    { NULL },     	/* parent type */
    { NULL },
    destruct,
    NULL                /* free by free() */
};
